package com.mercury.controller;

import com.mercury.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author ：tx
 * @description：视图解析器
 * @date ：Created in 2019/2/2 15:03
 * @modified By：
 * @version:
 */
@Controller
@RequestMapping("/userView")
public class UserViewController {

    @RequestMapping(value = "/register",method = RequestMethod.POST)
    public String sfForm(@Validated User user, Errors errors, Model model){  //errrors和model的先后顺序会不同？
        if(errors.hasErrors()){
            return "login";
        }
        model.addAttribute(user);
        return "sfFormView";
    }

    @RequestMapping("/index")
    public String index(Model model){
        model.addAttribute(new User("mercury","11"));
        return "login";
    }

    /**
     * @author tx
     * @description  tiles使用  返回值是对应tiles.xml中的值
     * @date  2019/2/22 14:57
     * @param  * @Param: model
     * @return java.lang.String
    **/
    @RequestMapping("/aa")
    public String getUserView(Model model){
        model.addAttribute(new User("mercury","11"));
        return "userView";
    }
}
